package com.taskcollection.servlet;

import com.taskcollection.bean.StudentBean;
import com.taskcollection.bean.TeacherBean;
import com.taskcollection.service.StudentService;
import com.taskcollection.service.TeacherService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * Created by Administrator on 2016/7/17 0017.
 */
@WebServlet(name = "RegServlet")
public class RegServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doGet(request,response);
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

        //获取注册信息
        String name = request.getParameter("name");
        String phone = request.getParameter("phone");
        String passwd = request.getParameter("passwd");
        String status = request.getParameter("status");
        System.out.println(status+"***********************");
        if("教师".equals(status)){
            //声明teacherservice对象
            TeacherService ts = new TeacherService();
            //声明teacherbean对象
            TeacherBean tea = new TeacherBean();
            tea.setTeacher_name(name);
            tea.setTeacher_phone(phone);
            tea.setTeacher_passwd(passwd);
            boolean flag = ts.reg(tea);
            if(!flag){
                response.sendRedirect(request.getContextPath()+"/teacher/homepage.jsp");
            }
        }else if("学生".equals(status)){
            System.out.println(status+"进入RegServlet");
            StudentService ss = new StudentService();
            StudentBean stu = new StudentBean();
            stu.setStudent_name(name);
            stu.setStudent_phone(phone);
            stu.setStudent_passwd(passwd);
            boolean flag = ss.reg(stu);
            if(!flag){
                response.sendRedirect(request.getContextPath()+"/teacher/homepage.jsp");
            }
        }

    }
}
